/*
 * Character class for the l2j server project
 * 
 */
package acm.characters.l2j;
/**
 * @author Emporeo
 * @web http://www.fai-communication.de/accountManager
 * @web source: http://code.google.com/p/mmo-account-manager/
 */

import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.ServletContext;
import acm.characters.Character;

public class Character_L2J extends Character {
	protected String charID,exp,sp,race;
	protected Vector<String> vAccountName,vCharID,vCharName,vLevel,vExp,vSP,vRace;
	protected Vector<String> vLastAccess,vClassName,vBaseClassName;

	public Character_L2J() {
		super();
	}

	/**
	 * @param context
	 */
	public Character_L2J(ServletContext context) {
		super(context);
	}
	
	
	/**
	 * 
	 * @param accountName
	 * @return Vectors with all Characters and character data for this account
	 */
	public void doGetAllCharacters(String accountName){
		try{
//		     Allocate and use a connection from the pool
		    con = dao.getDataSourceConnection(getContext());
			stmt = con.createStatement();
			
			sql ="SELECT c.account_name,c.charId,c.char_name,c.level, c.exp,c.sp,c.race,c.classid,c.base_class,c.lastAccess," +
			"ct.ClassName,ctBase.ClassName as BaseClassName "+
			"FROM characters c "+
			"INNER JOIN char_templates ct ON (c.classid = ct.classID) "+
			"INNER JOIN char_templates ctBase ON (c.base_class = ctBase.classID) "+
			"WHERE account_name="+"'"+accountName+"'";
			
			context.log(this.getClass().getName() + "Method:doGetAllCharacters: " + sql);
			
			vAccountName = new Vector<String>();
			vCharID= new Vector<String>();
			vCharName = new Vector<String>();
			vLevel = new Vector<String>();
			vExp = new Vector<String>();
			vSP = new Vector<String>();
			vRace = new Vector<String>();
			vLastAccess = new Vector<String>();
			vClassName = new Vector<String>();
			vBaseClassName = new Vector<String>();
			
//			Query absetzen
			pstmt = con.prepareStatement(sql);
			res = pstmt.executeQuery();
			
			while (res.next()){
				vAccountName.addElement(res.getString("account_name"));
				vCharID.addElement(res.getString("charId"));
				vCharName.addElement(res.getString("char_name"));
				vLevel.addElement(res.getString("level"));
				vExp.addElement(res.getString("exp"));
				vSP.addElement(res.getString("sp"));
				vRace.addElement(res.getString("race"));
				vLastAccess.addElement(res.getString("lastAccess"));
				vClassName.addElement(res.getString("ClassName"));
				vBaseClassName.addElement(res.getString("BaseClassName"));
			}
		
		}
		catch(SQLException SQLe){
			context.log(this.getClass().getName() + " - Method:doGetAllCharacters: "  + SQLe.getLocalizedMessage());
			this.setError(SQLe.getLocalizedMessage());
		}catch(Exception e){
			this.setError(e.toString());
			context.log(this.getClass().getName() + " - Method:doGetAllCharacters: "  + e.getMessage());
		}
		finally{
	    	try{stmt.close();}catch(Exception ex){};
	        try{con.close();}catch(Exception ex){};
		}
	}

	public String getCharID() {
		return charID;
	}

	public void setCharID(String charID) {
		this.charID = charID;
	}

	public String getExp() {
		return exp;
	}

	public void setExp(String exp) {
		this.exp = exp;
	}

	public String getSp() {
		return sp;
	}

	public void setSp(String sp) {
		this.sp = sp;
	}

	public String getRace() {
		return race;
	}

	public void setRace(String race) {
		this.race = race;
	}

	public Vector<String> getVAccountName() {
		return vAccountName;
	}

	public void setVAccountName(Vector<String> accountName) {
		vAccountName = accountName;
	}

	public Vector<String> getVBaseClassName() {
		return vBaseClassName;
	}

	public void setVBaseClassName(Vector<String> baseClassName) {
		vBaseClassName = baseClassName;
	}

	public Vector<String> getVCharID() {
		return vCharID;
	}

	public void setVCharID(Vector<String> charID) {
		vCharID = charID;
	}

	public Vector<String> getVCharName() {
		return vCharName;
	}

	public void setVCharName(Vector<String> charName) {
		vCharName = charName;
	}

	public Vector<String> getVClassName() {
		return vClassName;
	}

	public void setVClassName(Vector<String> className) {
		vClassName = className;
	}

	public Vector<String> getVExp() {
		return vExp;
	}

	public void setVExp(Vector<String> exp) {
		vExp = exp;
	}

	public Vector<String> getVLastAccess() {
		return vLastAccess;
	}

	public void setVLastAccess(Vector<String> lastAccess) {
		vLastAccess = lastAccess;
	}

	public Vector<String> getVLevel() {
		return vLevel;
	}

	public void setVLevel(Vector<String> level) {
		vLevel = level;
	}

	public Vector<String> getVRace() {
		return vRace;
	}

	public void setVRace(Vector<String> race) {
		vRace = race;
	}

	public Vector<String> getVSP() {
		return vSP;
	}

	public void setVSP(Vector<String> vsp) {
		vSP = vsp;
	}
	

}
